package reduce.fz.com.reduce.custom.inter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.android.volley.Response;
import com.android.volley.Response.ErrorListener;
import com.android.volley.VolleyError;

import java.util.List;

import reduce.fz.com.reduce.bean.result.Result;
import reduce.fz.com.reduce.util.JsonUtil;
import reduce.fz.com.reduce.util.ToastUtil;

/**
 * Created by qingshengzheng on 15/7/20.
 */
public abstract class AbstractResponse<T> implements Response.Listener, Response.ErrorListener {

    @Override
    public void onErrorResponse(VolleyError volleyError) {
        volleyError.printStackTrace();


    }

    @Override
    public void onResponse(Object o) {
        Result<T> result = JsonUtil.convert(o.toString(), new TypeReference<Result<T>>() {
        });
        onSuccess(result);
    }

    protected abstract void onSuccess(Result<T> result);
}
